package xj.graph2d.app.prop;

import java.awt.Color;
import java.awt.Font;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class TitleComponent extends JPanel { 

  public TitleComponent() { 
    this(null, false); 
  }

  public TitleComponent(boolean hasEntries) { 
    this(null, hasEntries); 
  }

  public TitleComponent(String prefix) { 
    this(prefix, false);
  }

  public TitleComponent(String prefix, boolean hasEntries) { 
    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
    prefixLabel = new JLabel(prefix);
    nameLabel = new JLabel();
    elementLabel = new JLabel();
    add(prefixLabel);
    add(Box.createHorizontalStrut(6));
    if (hasEntries) { 
      entryLabel = new JLabel();
      add(entryLabel);
      add(Box.createHorizontalStrut(6));      
      add(new JLabel("of"));
      add(Box.createHorizontalStrut(6));      
    }
    add(nameLabel);
    add(Box.createHorizontalStrut(6));
    add(elementLabel);
  }

  public void setPrefix(String prefix) {
    prefixLabel.setText(prefix); 
  }

  public void setPrefixStyle(int style) { 
    Font f = prefixLabel.getFont();
    int size = f.getSize(); 
    f = f.deriveFont(style, size); 
    prefixLabel.setFont(f);
  }

  public void setPrefixColor(Color c) { 
    prefixLabel.setForeground(c);
  }

  public void setEntry(String entry) {
    if (entryLabel != null) { 
      entryLabel.setText(entry);
    } 
  }

  public void setEntryStyle(int style) { 
    if (entryLabel != null) { 
      Font f = entryLabel.getFont();
      int size = f.getSize(); 
      f = f.deriveFont(style, size); 
      entryLabel.setFont(f);
    }
  }

  public void setEntryColor(Color c) {     
    if (entryLabel != null) { 
      entryLabel.setForeground(c);
    }
  }

  @Override
public void setName(String name) {
    nameLabel.setText(name); 
  }

  public void setNameStyle(int style) { 
    Font f = nameLabel.getFont();
    int size = f.getSize(); 
    f = f.deriveFont(style, size); 
    nameLabel.setFont(f);
  }

  public void setNameColor(Color c) { 
    nameLabel.setForeground(c);
  }

  public void setElement(String element) { 
    elementLabel.setText(element); 
  }

  public void setElementStyle(int style) { 
    Font f = elementLabel.getFont();
    int size = f.getSize(); 
    f = f.deriveFont(style, size); 
    elementLabel.setFont(f);
  }

  public void setElementColor(Color c) { 
    elementLabel.setForeground(c);
  }

  public void setTitle(String prefix, String name) { 
    setTitle(prefix, name, null);
  }

  public void setTitle(String prefix, String name, String element) { 
    setPrefix(prefix); 
    setName(name);
    setElement(element);
  }

  protected JLabel prefixLabel, nameLabel, elementLabel, entryLabel;

}
